<?php

namespace app\modules\setting\models\workspaces;

use yii\helpers\Json;

/**
 * This is the model class for table "{{%set_workspaces_yhsp}}".
 *
 * @property int $id
 * @property string $tk_id id
 * @property string $description 简介
 * @property string $create_time create_time
 * @property string $collect_count collectCount
 * @property string $comment_count commentCount
 * @property string $digg_count diggCount
 * @property string $play_count playCount
 * @property string $share_count shareCount
 * @property string $thumbnail thumbnail
 * @property string $display_url display_url
 * @property string $video video信息
 * @property string $music 音乐信息
 * @property string $update_at 最后更新时间
 */
class SetWorkspacesYhsp extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%set_workspaces_yhsp}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['tk_id', 'description', 'create_time', 'collect_count', 'comment_count', 'digg_count', 'play_count', 'share_count', 'thumbnail', 'display_url', 'video', 'music', 'update_at'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            
            'id' => 'ID',
            
            'tk_id' => 'id',
            
            'description' => '简介',
            
            'create_time' => 'create_time',
            
            'collect_count' => 'collectCount',
            
            'comment_count' => 'commentCount',
            
            'digg_count' => 'diggCount',
            
            'play_count' => 'playCount',
            
            'share_count' => 'shareCount',
            
            'thumbnail' => 'thumbnail',
            
            'display_url' => 'display_url',
            
            'video' => 'video信息',
            
            'music' => '音乐信息',
                                    
            'update_at' => '最后更新时间',
        ];
    }


    public function beforeValidate()
    {
        foreach ($this->attributes() as $field){
            if (is_array($this->$field)){
                $this->$field = Json::encode($this->$field);
            }
        }

        return parent::beforeValidate(); // TODO: Change the autogenerated stub
    }

    public function getFirstErrorStr()
    {
        $errors = $this->getErrors();

        if ($errors){
            foreach ($errors as $item){
                return $item[0];
            }
        }

        return "";
    }
}
